package com.leozhang.app;

import com.github.yitter.contract.IdGeneratorOptions;
import com.github.yitter.idgen.YitIdHelper;

import java.util.HashSet;
import java.util.Set;

public class App {

    public static void main(String[] args) {
        // 配置 ID 生成器选项
        IdGeneratorOptions options = new IdGeneratorOptions((short) 24);
        //short id = 1;
        //options.setWorkerId(id); // 设置 Worker ID
        //options.setDataCenterId(1); // 设置 Data Center ID

        YitIdHelper.setIdGenerator(options);

        // 生成并测试唯一性
        int numberOfIds = 1000000; // 生成的 ID 数量
        Set<Long> idSet = new HashSet<>(numberOfIds);
        
        boolean hasDuplicate = false;
        
        for (int i = 0; i < numberOfIds; i++) {
            long id = YitIdHelper.nextId();
            System.out.println(id);
            if (!idSet.add(id)) {
                System.out.println("Duplicate ID found: " + id);
                hasDuplicate = true;
                break;
            }
        }

        if (!hasDuplicate) {
            System.out.println("No duplicates found in " + numberOfIds + " IDs.");
        }
    }
}
